package com.study.lease.common.exception;

import com.study.lease.common.result.Result;
import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.rmi.dgc.Lease;

/**
 * 全局异常处理
 * 全局异常处理功能由SpringMVC提供，因此需要导入Spring—web的依赖包
 */

@Hidden
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handle(Exception e){
        e.getMessage();
        e.printStackTrace();
        return Result.fail();
    }

    /**
     * 处理公寓管理中删除时房间存在异常
     * @param e
     * @return
     */
    @ExceptionHandler(LeaseException.class)
    @ResponseBody
    public Result handle(LeaseException e){
        e.printStackTrace();
        return Result.fail(e.getCode(),e.getMessage());
    }
}